//该文件专门用于创建整个应用的路由器
import VueRouter from "vue-router";
//引入自定义的组件
import RootPerson from '@/pages/RootPerson'
import ClientelePerson from '@/pages/ClientelePerson'
import GameCategory from '@/pages/GameCategory'
import GamesPage from '@/pages/GamesPage'
import GameSpecification from '@/pages/GameSpecification'
import ManagerLogin from '@/pages/ManagerLogin'
import ShowSet from '@/pages/ShowSet'
import DiscountManage from '@/pages/DiscountManage'
import OrderShow from '@/pages/OrderShow'
//创建一个路由器并暴露
/*最低权限页面：登陆页面，什么限制都不用加
    普通权限页面：商业管理相关页面，加限制 meta:{manager:true}
    最高权限页面：管理员管理页面，加限制 meta:{manager:true,root:true}
*/
const router= new VueRouter({
    routes:[
        {
            name:'getRoots',
            path:'/roots/:page/:pageSize',
            component:RootPerson,
            props($route){
                return{
                    page:$route.params.page,
                    pageSize:$route.params.pageSize
                }
            },
            meta:{manager:true,root:true}
        },
        {
            name:'getClientele',
            path:'/clientele/:page/:pageSize',
            component:ClientelePerson,
            props($route){
                return{
                    page:$route.params.page,
                    pageSize:$route.params.pageSize
                }
            },
            meta:{manager:true}
        },
        {
            name:'getGameCategory',
            path:'/gameCategory/:page/:pageSize',
            component:GameCategory,
            props($route){
                return{
                    page:$route.params.page,
                    pageSize:$route.params.pageSize
                }
            },
            meta:{manager:true}
        },
        {
            name:'getGames',
            path:'/games/:page/:pageSize',
            component:GamesPage,
            props($route){
                return{
                    page:$route.params.page,
                    pageSize:$route.params.pageSize
                }
            },
            meta:{manager:true}
        },
        {
            name:'getGameSpecification',
            path:'/gameSpecification/:page/:pageSize',
            component:GameSpecification,
            props($route){
                return{
                    page:$route.params.page,
                    pageSize:$route.params.pageSize
                }
            },
            meta:{manager:true}
        },
        {
            name:'showSet',
            path:'/showSet',
            component:ShowSet,
            meta:{manager:true}
        },
        {
            name:'managerLogin',
            path:'/managerLogin',
            component:ManagerLogin,//特殊，登陆页面毫无任何进入权限设置
        },
        {
            name:'discountManage',
            path:'/discountManage',
            meta:{manager:true},
            component:DiscountManage,
        },
        {
            name:'orderShow',
            path:'/orderShow/:page/:pageSize',
            meta:{manager:true},
            props($route){
                return{
                    page:$route.params.page,
                    pageSize:$route.params.pageSize
                }
            },
            component:OrderShow,
        }
    ]
});
router.beforeEach((to,from,next)=>{
    const obj=JSON.parse(localStorage.getItem('managerData'));
    if(obj===null||obj.canUse===false){//未登录或者帐号状态禁用则只能访问登录页
        if(to.meta.manager===undefined){
            next();
        }
    }else{//登陆状态并且帐号状态正常
        if(obj.root===true){//超级管理员
            next();
        }else if(to.meta.root===undefined){//非超级管理员
            next();
        }
    }
})

export default router;